#ifndef FIREFOXHANDLER_H
#define FIREFOXHANDLER_H

#include "firefoxhandler_global.h"
#include <chrono>

class Server;
class FirefoxHandler
{
private:
    FirefoxHandler();
public:
    ~FirefoxHandler();
public:
    static std::pair<bool, QString> openTab(const QString &url, std::chrono::milliseconds timeout = operationTimeout());
    static std::pair<bool, QVariant> runScriptOnTab(const QString &tabstr, const QString &content, std::chrono::milliseconds timeout = operationTimeout());
    static std::pair<bool, QVariant> runFunctionOnAddon(const QString &name, const QVariantList &args, std::chrono::milliseconds timeout = operationTimeout());
    static std::pair<bool, QVariant> runFunctionOnTab(const QString &tabstr, const QString &name, const QVariantList &args, std::chrono::milliseconds timeout = operationTimeout());
    static std::chrono::milliseconds operationTimeout();
    static void setOperationTimeout(const std::chrono::milliseconds &timeout);
private:
    std::chrono::milliseconds _operationTimeout = std::chrono::milliseconds(2000);
public:
    static bool init();
    // public static methods:
    static FirefoxHandler *instance();
public:
    QObject *topObject = nullptr;
private:
    // internal static variables
    static FirefoxHandler *_instance;
};

#endif // FIREFOXHANDLER_H
